package insight;

/**
 * @author huu
 * @create 2025-08-25-11:17
 */
public class Main {
    public static void main(String[] args) throws InterruptedException {
        //事件驱动模型，生成事件然后通知订阅者，字符转作为事件
//        WeatherStation weatherStation = new WeatherStation();
//        User huu = new User("huu", ( info)->{
//            if(info.equals("晴天")){
//                System.out.println("用户huu，今天是晴天，请出去玩");
//            }else{
//                System.out.println("用户huu，今天是阴天，请 Stay at home");
//            }
//        });
//        User user = new User("huu", ( info)->{
//            if(info.equals("阴天")){
//                System.out.println("用户1，今天是阴天，请出去玩");
//            }else{
//                System.out.println("用户2，今天是阴天，请 Stay at home");
//            }
//        });
//        weatherStation.subscribe(huu);
//        weatherStation.subscribe(user);
//        weatherStation.start();
        //观察者模式 --> 事件产生者直接去监听
        //发布订阅  ——> 事件产生者 - 总线 - 订阅者
        TVStation tvStation = new TVStation();
        WeatherStation weatherStation = new WeatherStation(tvStation);
        User huu = new User("huu", ( info)->{
            if(info.equals("晴天")){
                System.out.println("用户huu，今天是晴天，请出去玩");
            }else{
                System.out.println("用户huu，今天是阴天，请 Stay at home");
            }
        });
        User user = new User("huu", (info)->{
            if(info.equals("阴天")){
                System.out.println("用户1，今天是阴天，请出去玩");
            }else{
                System.out.println("用户2，今天是阴天，请 Stay at home");
            }
        });
        tvStation.subscribe(huu, WeatherUpdateEvent.class);
        tvStation.subscribe(user, WeatherUpdateEvent.class);
        weatherStation.start();
    }
}
